package org.chengn.level_easy.context2706;

/**
 * @Title: Context2706
 * @Author ChengN
 * @Package org.chengn.level_easy.context2706
 * @Date 2023/12/29 0:12
 * @description: 购买两块巧克力
 */
public class Context2706 {
    public int buyChoco(int[] prices, int money) {
        int[] ans = new int[2];
        ans[0] = prices[0];
        ans[1] = prices[1];
        for (int i = 2; i < prices.length; ++i) {
            ans[1] = Math.min(ans[1], Math.max(ans[0], prices[i]));
            ans[0] = Math.min(ans[0], prices[i]);
        }

        int sum = money - ans[0] - ans[1];
        return sum >= 0 ? sum : money;
    }
}
